{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "jupyter",
     "locked": true,
     "schema_version": 3,
     "solution": false
    }
   },
   "source": [
    "For this problem set, we'll be using the Jupyter notebook:\n",
    "\n",
    "![](jupyter.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Part A (2 points)\n",
    "\n",
    "Write a function that returns a list of numbers, such that $x_i=i^2$, for $1\\leq i \\leq n$. Make sure it handles the case where $n<1$ by raising a `ValueError`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "squares",
     "locked": false,
     "schema_version": 3,
     "solution": true
    }
   },
   "outputs": [],
   "source": [
    "def squares(n):\n",
    "    \"\"\"Compute the squares of numbers from 1 to n, such that the \n",
    "    ith element of the returned list equals i^2.\n",
    "    \n",
    "    \"\"\"\n",
    "    ### BEGIN SOLUTION\n",
    "    if n < 1:\n",
    "        raise ValueError(\"n must be greater than or equal to 1\")\n",
    "    return [i ** 2 for i in range(1, n + 1)]\n",
    "    ### END SOLUTION"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Your function should print `[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]` for $n=10$. Check that it does:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "correct_squares",
     "locked": false,
     "points": 1,
     "schema_version": 3,
     "solution": false
    }
   },
   "outputs": [],
   "source": [
    "\"\"\"Check that squares returns the correct output for several inputs\"\"\"\n",
    "assert squares(1) == [1]\n",
    "assert squares(2) == [1, 4]\n",
    "assert squares(10) == [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n",
    "assert squares(11) == [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "pedal_squares",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "\n",
       "    console.log(\"HEY WAIT WHY\");\n",
       "    var output_area = this;\n",
       "    // find my cell element\n",
       "    var cell_element = output_area.element.parents('.cell');\n",
       "    // which cell is it?\n",
       "    var cells = Jupyter.notebook.get_cells();\n",
       "    var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n",
       "    // TODO: Walk backwards to get last \"Autograded Answer\" cell\n",
       "    // get the cell object\n",
       "    let cell = null;\n",
       "    for (let i= cell_idx; i > 0; i -= 1) {\n",
       "        cell = Jupyter.notebook.get_cell(i);\n",
       "        if (cell.metadata.nbgrader && cell.metadata.nbgrader.solution) {\n",
       "            break;\n",
       "        }\n",
       "    }\n",
       "    let instructor_cell = Jupyter.notebook.get_cell(cell_idx);\n",
       "    let instructor_text = instructor_cell.get_text();\n",
       "    instructor_text = instructor_text.split(\"\\n\")\n",
       "                                     .slice(4)\n",
       "                                     .join(\"\\n\");\n",
       "    console.log('>>>', instructor_text);\n",
       "    let source_code = \"\";\n",
       "    if (cell !== null) {{\n",
       "        source_code = cell.get_text();\n",
       "    }}\n",
       "\n",
       "    var kernel = Jupyter.notebook.kernel;\n",
       "    var get_source_code = \"student_code=\"+JSON.stringify(source_code);\n",
       "    get_source_code += `\n",
       "from pedal.environments.nbgrader import NBGraderEnvironment\n",
       "NBGraderEnvironment(main_code=student_code)\n",
       "if True:\n",
       "`+instructor_text;\n",
       "    console.log(get_source_code);\n",
       "    if (kernel !== null) {\n",
       "        console.log(\"DOUBLE CHECK\");\n",
       "        console.log(kernel.execute(get_source_code, {\n",
       "            iopub: {\n",
       "                output: (data) => {\n",
       "                    //console.log(\">>>\", data, output_area, instructor_cell);\n",
       "                    if (data.msg_type !== \"error\" || data.content.ename !== \"PedalNotebookException\") {\n",
       "                        output_area.handle_output(data);\n",
       "                    } else {\n",
       "                        console.error(\"Pedal Exception:\", data);\n",
       "                    }\n",
       "                    /*\n",
       "                    console.log('+++', data);\n",
       "                    console.log(output_area);\n",
       "                    console.log(cell_element);\n",
       "                    console.log(instructor_cell);\n",
       "                    data.output_type = data.msg_type;\n",
       "                    instructor_cell.outputs.push(data);\n",
       "                    if (data.msg_type == \"error\") {\n",
       "                        // If this was an error, show the traceback properly.\n",
       "                        output_area.append_error(data.content);\n",
       "                        console.error(data);\n",
       "                    } else if (data.msg_type === \"display_data\") {\n",
       "                        // If it was valid data, we show it as HTML.\n",
       "                        console.log(data);\n",
       "                        output_area.append_display_data(data.content);\n",
       "                        instructor_cell.outputs.push(data.content);\n",
       "                        //output_area.element.html(output_area.element.html()+\"\\n\"+\n",
       "                        //                         data.content.text.replace(/\\n/g, \"<br>\"));\n",
       "                    } else {\n",
       "                        // I'm not sure what it is - better dump it on the console.\n",
       "                        console.log(data);\n",
       "                    }\n",
       "                */}\n",
       "            }\n",
       "        }));\n",
       "    }\n",
       "    console.log(\"FINISHED SETTING UP JS\");\n",
       "    "
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "ename": "AssertionError",
     "evalue": "You used an IF statement on line 7. You may not use that.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAssertionError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-6-f0ea7d05bcf8>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mNBGraderEnvironment\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmain_code\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstudent_code\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m     \u001b[0mprevent_ast\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"If\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      6\u001b[0m     \u001b[0mprevent_ast\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"If\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m     \u001b[0mprevent_embedded_answer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\acbart\\projects\\pedal-edu\\pedal\\pedal\\assertions\\static.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, name, at_most, root, **kwargs)\u001b[0m\n\u001b[0;32m     44\u001b[0m         fields = {'name': name, 'at_most': at_most, 'capacity': '',\n\u001b[0;32m     45\u001b[0m                   'root': root, 'name_message': report.format.name(name)}\n\u001b[1;32m---> 46\u001b[1;33m         \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfields\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfields\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     47\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     48\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_check_usage\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfield_name\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muses\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\acbart\\projects\\pedal-edu\\pedal\\pedal\\core\\feedback.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, label, category, justification, fields, field_names, kind, title, message, message_template, else_message, priority, valence, location, score, correct, muted, unscored, tool, version, author, tags, parent, report, delay_condition, activate, *args, **kwargs)\u001b[0m\n\u001b[0;32m    240\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_status\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mFeedbackStatus\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDELAYED\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    241\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 242\u001b[1;33m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_handle_condition\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    243\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    244\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\acbart\\projects\\pedal-edu\\pedal\\pedal\\core\\feedback.py\u001b[0m in \u001b[0;36m_handle_condition\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    261\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreport\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    262\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_met_condition\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 263\u001b[1;33m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreport\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_feedback\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    264\u001b[0m             \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    265\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreport\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_ignored_feedback\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\acbart\\projects\\pedal-edu\\pedal\\pedal\\core\\report.py\u001b[0m in \u001b[0;36madd_feedback\u001b[1;34m(self, feedback)\u001b[0m\n\u001b[0;32m    138\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfeedback\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparent\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfeedback\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparent\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    139\u001b[0m             \u001b[0mfeedback\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_child_feedback\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfeedback\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 140\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute_hooks\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'pedal.report'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'add_feedback'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfeedback\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    141\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mfeedback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    142\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\acbart\\projects\\pedal-edu\\pedal\\pedal\\core\\report.py\u001b[0m in \u001b[0;36mexecute_hooks\u001b[1;34m(self, tool, event_name, arguments, keyword_arguments)\u001b[0m\n\u001b[0;32m    231\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mevent\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhooks\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    232\u001b[0m             \u001b[1;32mfor\u001b[0m \u001b[0mfunction\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhooks\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mevent\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 233\u001b[1;33m                 \u001b[0mfunction\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mreport\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0marguments\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkeyword_arguments\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    234\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    235\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m__getitem__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtool_name\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\acbart\\projects\\pedal-edu\\pedal\\pedal\\environments\\nbgrader.py\u001b[0m in \u001b[0;36mforce_immediate_errors\u001b[1;34m(self, feedback, report)\u001b[0m\n\u001b[0;32m    208\u001b[0m                 \u001b[0mexc_type\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtraceback\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    209\u001b[0m                 \u001b[0mtraceback\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtb_next\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 210\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mexc_type\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtraceback\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    211\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    212\u001b[0m         \u001b[1;31m#if in_notebook():\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\acbart\\projects\\pedal-edu\\pedal\\pedal\\environments\\nbgrader.py\u001b[0m in \u001b[0;36mforce_immediate_errors\u001b[1;34m(self, feedback, report)\u001b[0m\n\u001b[0;32m    203\u001b[0m         \u001b[1;32mwith\u001b[0m \u001b[0mtc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msubTest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    204\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 205\u001b[1;33m                 \u001b[0mtc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfinal\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    206\u001b[0m             \u001b[1;32mexcept\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    207\u001b[0m                 \u001b[1;31m# Remove traceback info as we don't need it\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAssertionError\u001b[0m: You used an IF statement on line 7. You may not use that."
     ]
    }
   ],
   "source": [
    "from pedal import *\n",
    "from pedal.environments.nbgrader import setup_environment\n",
    "\n",
    "if setup_environment('squares'):\n",
    "    prevent_ast(\"If\")\n",
    "    prevent_ast(\"If\")\n",
    "    prevent_embedded_answer(1)\n",
    "    prevent_import('numpy')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "squares_invalid_input",
     "locked": false,
     "points": 1,
     "schema_version": 3,
     "solution": false
    }
   },
   "outputs": [],
   "source": [
    "\"\"\"Check that squares raises an error for invalid inputs\"\"\"\n",
    "try:\n",
    "    squares(0)\n",
    "except ValueError:\n",
    "    pass\n",
    "else:\n",
    "    raise AssertionError(\"did not raise\")\n",
    "\n",
    "try:\n",
    "    squares(-4)\n",
    "except ValueError:\n",
    "    pass\n",
    "else:\n",
    "    raise AssertionError(\"did not raise\")"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Create Assignment",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
